<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>${message("添加会员")}</title>
<link href="/resources/css/common.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/resources/js/reference/jquery.js"></script>
<script type="text/javascript" src="/resources/js/reference/jquery.validate.js"></script>
<script type="text/javascript" src="/resources/js/base/dialog.js"></script>
<script type="text/javascript" src="/resources/js/base/request.js"></script>
<script type="text/javascript" src="/resources/js/base/global.js"></script>
<script type="text/javascript" src="/resources/plugin/datePicker/WdatePicker.js"></script>
<link href="/resources/css/mmGrid.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/resources/js/reference/mmGrid.js"></script>
<script src="/resources/js/base/file.js"></script>
<script type="text/javascript">
$().ready(function() {
	var $inputForm = $("#inputForm");
	var $addTerminal = $("#addTerminal");
	var $deleteTerminal = $("a.deleteTerminal");
	
	// 表单验证
	$inputForm.validate({
		rules: {
			username: {
				required: true,
				minlength: ${setting.usernameMinLength},
				maxlength: ${setting.usernameMaxLength}
			},
			mobile: {
				required:true
			},
			password: {
				pattern: /^[^\s&\"<>]+$/,
				minlength: ${setting.passwordMinLength},
				maxlength: ${setting.passwordMaxLength},
				required: true
			},
			rePassword: {
				equalTo: "#password",
				required: true
			},
			pinCode: {
				required: true,
				pattern: /^\w+$/,
				minlength: 6,
				maxlength: 6
			},
			operatePassword: {
				required: true,
				pattern: /^[^\s&\"<>]+$/,
				minlength: 6,
				maxlength: 6
			}
		},
		messages: {
			username: {
				pattern: "${message("非法字符")}",
				remote: "${message("已存在")}"
			},
			password: {
				pattern: "${message("非法字符")}"
			},
			operatePassword: {
				pattern: "${message("非法字符")}"
			},
			pinCode: {
				pattern: "${message("非法字符")}"
			}
			[#if !setting.isDuplicateEmail]
				,email: {
					remote: "${message("已存在")}"
				}
			[/#if]
		},
	});
	
	//查询机构
	$("#selectSaleOrg").bindQueryBtn({
		type:'saleOrg',
		title:'${message("查询机构")}',
		url:'/saleOrg/select_saleOrg.jhtml'
	});
	 $("form").bindAttribute({
	 	isConfirm:true,
	    callback: function(resultMsg){
	        $.message_timer(resultMsg.type,resultMsg.content,1000,function(){
				location.href= 'edit.jhtml?id='+resultMsg.objx;
			})
	    }
	 });
	 
	 //打开选择终端设备界面
    $addTerminal.click(function(){
        $addTerminal.bindQueryBtn({
            type:'terminal',
            bindClick:false,
            title:'${message("查询终端设备")}',
            url:'/terminal/select_list.jhtml?multi=2',
            callback:function(rows){
                if(rows.length>0){
                    for (var i = 0; i < rows.length;i++) {
                        var idH = $(".terminalId_"+rows[i].id).length;
                        if(idH > 0){
                            $.message_alert('终端设备编号【'+rows[i].terminal_num+'】已添加');
                            return false;
                        }
                    }
                    for (var i = 0; i < rows.length;i++) {
						var row = rows[i];
						$tmGrid.addRow(row,null,1);
					}
                }
            }
        }); 
    })
	 
	 var terminalInItemIndex = 0;
 	var cols = [				
    	{ title:'${message("终端设备编号")}', name:'terminal_num' ,align:'center', width:110, renderer: function(val,item,rowIndex, obj){
			var	html = '<input type="hidden" name="terminalId" class="terminalId terminalId_'+item.id+'" value="'+item.id+'" />'+val;
			return html;}
		},
    	{ title:'${message("终端名称")}', name:'terminal_name' ,align:'center', width:110},
    	{ title:'${message("终端SIM卡号")}', name:'sim' ,align:'center', width:110},
		{ title:'${message("操作")}', align:'center', width:60, renderer:function(val,item){
		terminalInItemIndex++;
		return '<a href="javascript:;" class="deleteTerminal btn-delete">删除</a>';
		}},
	];
	var $tmGrid=$('#table-terminal').mmGrid({
		fullWidthRows:true,
		height:'auto',
        cols: cols,
        checkCol: false,
        autoLoad: true,
         callback:function(){
         }
    });
    
      
    // 删除终端设备
    $deleteTerminal.live("click", function() {
        var index = $(this).closest("tr").index();
		$.message_confirm('您确定要删除吗？',function(){
			$tmGrid.removeRow(index);
		})
    });
    
});	
</script>
</head>
<body>
	<div class="pathh">
		&nbsp;${message("新增用户")}
	</div>
	<form id="inputForm" action="save.jhtml" method="post" type="ajax" validate-type="validate">
		<div class="tabContent">
			<table class="input input-edit">
			[#if memberType==1]
			[#else]
			<tr>
				<th>
					<span class="requiredField">*</span>${message("15023")}:
				</th>
				<td>
					<span class="error-msg"><input type="text" name="username" class="text " maxlength="20"   btn-fun="clear"/></span>
				</td>
				<th>
					<span class="requiredField">*</span>${message("手机")}:
				</th>
				<td>
					<span class="error-msg"><input type="text" name="mobile" class="text " maxlength="20"   btn-fun="clear" autocomplete="off"/></span>
				</td>
				<th>
					<span class="requiredField">*</span>${message("登录密码")}:
				</th>
				<td>
					<span class="error-msg"><input type="text" id="password" name="password" class="text " maxlength="20" btn-fun="clear" autocomplete="off" onfocus="this.type='password'" /></span>
				</td>
				<th>
					<span class="requiredField">*</span>${message("确认登陆密码")}:
				</th>
				<td>
					<span class="error-msg"><input type="text" name="rePassword" class="text " maxlength="20" btn-fun="clear" autocomplete="off" onfocus="this.type='password'"/></span>
				</td>
			</tr>
			[/#if]
			<tr>
				<th>
					<span class="requiredField">*</span>${message("机构")}:
				</th>
				<td>
					<span class="search" style="position:relative">
					<input type="hidden" name="saleOrgId" class="text saleOrgId" btn-fun="clear" value="${saleOrg.id }"/>
					<input type="text" name="saleOrgName" class="text saleOrgName" maxlength="200" onkeyup="clearSelect(this)" value="${saleOrg.name }" readOnly/>
					<input type="button" class="iconSearch" value="" id="selectSaleOrg">
					</span>
				</td>
				<!--<th>
					<span class="requiredField">*</span>${message("12500")}:
				</th>
				<td>
					<span class="search" style="position:relative">
							<input type="hidden" name="memberRankId" class="text memberRankId" id="memberRankId" btn-fun="clear" />
							<input type="text" name="memberRankName" class="text memberRankName" maxlength="200" onkeyup="clearSelect(this)" id="memberRankName" />
							<input type="button" class="iconSearch" value="" id="selectMemberRank">
						</span>
				</td>-->
				<th>
					${message("姓名")}:
				</th>
				<td>
					<input type="text" name="name" class="text" maxlength="200"  btn-fun="clear"/>
				</td>
				<th>
					${message("用户类型")}:
				</th>
				<td>
					<!-- <label><input type="radio" name="memberType" value="0" checked="checked" />业务系统用户</label>
					<label><input type="radio" name="memberType" value="1"/>操作终端用户</label> -->
					<input type="hidden" name="memberType" value="${memberType}"/>
					[#if memberType==1]操作终端用户[#else]业务系统用户[/#if]
				</td>
				<th>
				</th>
				<td>
				</td>
			</tr>
			<tr>
				[#if memberType==1]
				<th>
					${message("操作员PIN码")}:
				</th>
				<td>
					<span class="error-msg"><input type="text" id="pinCode" name="pinCode" class="text [#if member.memberType==1]psw[/#if]" maxlength="20"   btn-fun="clear"  autocomplete="off"/></span>
				</td>
				<th>
					${message("操作终端密码")}:
				</th>
				<td>
					<span class="error-msg">
					<input type="password"  style="display:none"/>   
					<input type="text" id="operatePassword" name="operatePassword" class="text [#if member.memberType==1]psw[/#if]" maxlength="20" btn-fun="clear" autocomplete="off" /></span>
				</td>
				[/#if]
				<th>
					${message("16035")}:
				</th>
				<td colspan="[#if memberType==1]3[#else]7[/#if]">
					<label>
						<input type="checkbox" name="isEnabled" value="true" checked="checked" />${message("16045")}
						<input type="hidden" name="_isEnabled" value="false" />
					</label>&nbsp;&nbsp;&nbsp;
					
				</td>
			</tr>
			[#if memberType==0]
			<tr id ="role_type">
				<th>
					${message("所属角色")}:
				</th>
				<td colspan="7">
					<span class="fieldSet">
						[#list roles as role]
							<label>
								<input id="roleId" type="checkbox" name="roleId" value="${role.id}"/>${role.name}
							</label>&nbsp;&nbsp;&nbsp;
						[/#list]
					</span>
				</td>
			</tr>
			[/#if]
			<!-- <tr>
				<th>${message("头像")}</th>
				<td colspan="7"><input type="hidden" name="imageName" ></td>
			</tr> -->
			[#if memberType==1]
			 <tr class="border-L2">
                <th>${message("操作终端设备")}:</th>
                <td colspan="7">
	                <a href="javascript:;" id="addTerminal" class="button">选择操作终端设备</a>
                </td>
            </tr>
           <tr class="border-L2">
            	<td colspan="8">
            		<div>
						<table id="table-terminal"></table>
					</div>
            	</td>
            </tr>
            [/#if]
		</table>
		</div>
		<div class="fixed-top">
			<input type="submit" id="submit_button" class="button sureButton" value="${message("1013")}" />
			<input type="button" onclick="location.reload(true);" class="button resetButton ml15" value="${message("重置")}">
		</div>
	</form>
</body>
</html>